﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace VirtualPress.Infrastructure.Entities.Repository
{
    [Table("T_AuditingRecord")]
    public class T_AuditingRecord : IEntity<T_AuditingRecord>
    {
        [Key]
        [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        public int JournalId { get; set; }
        public int MeetingId { get; set; }

        /// <summary>
        /// 任务分发者
        /// </summary>
        [Column(TypeName="nvarchar")]
        [StringLength(64)]
        public string Distributor { get; set; }

        public int ManuscriptId { get; set; }

        /// <summary>
        /// 专家用户名
        /// </summary>
        [Column(TypeName="nvarchar")]
        [StringLength(64)]
        public string UserName { get; set; }

        /// <summary>
        /// 待审核 = 1
        /// 完成未提交 = 2
        /// 审核完成 = 3
        /// 拒绝 = 4
        /// 取消 = 9
        /// </summary>
        public int ExamineStatus { get; set; }

        /// <summary>
        /// 初审 = 1,
        /// 专审 = 2,
        /// 终审 = 3
        /// </summary>
        public int Step { get; set; }

        [Column(TypeName="text")]
        public string Message { get; set; }

        /// <summary>
        /// 创建记录时间
        /// </summary>
        [Column(TypeName="datetime")]
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 上一次操作记录时间
        /// </summary>
        [Column(TypeName="datetime")]
        public DateTime LastRecord { get; set; }
        /// <summary>
        /// 要求审稿完成时间
        /// </summary>
        [Column(TypeName = "datetime")]
        public DateTime ExamineFinishDate { get; set; }
        
        /// <summary>
        /// 审稿单id
        /// </summary>
        public int AppendixId { get; set; }

        /// <summary>
        /// 稿件类型
        /// </summary>
        [Column(TypeName="nvarchar")]
        [StringLength(32)]
        public string ManuscriptType { get; set; }

        /// <summary>
        /// 原创性
        /// </summary>
        [Column(TypeName="nvarchar")]
        [StringLength(32)]
        public string Originality { get; set; }

        /// <summary>
        /// 实用性
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(32)]
        public string Usefulness { get; set; }

        /// <summary>
        /// 技术合理性
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(32)]
        public string Soundness { get; set; }

        /// <summary>
        /// 语言描述
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(32)]
        public string LinguisticQuality { get; set; }

        /// <summary>
        /// 稿件解决了什么问题
        /// </summary>
        [Column(TypeName = "text")]
        public string Resolution { get; set; }

        /// <summary>
        /// 主要领域作出的贡献
        /// </summary>
        [Column(TypeName = "text")]
        public string Contribution { get; set; }

        /// <summary>
        /// 在哪些方面确实缺乏原创
        /// </summary>
        [Column(TypeName = "text")]
        public string Originalless { get; set; }
        /// <summary>
        /// 审核意见类型
        /// 0：推荐接收
        /// 1：接收
        /// 2：需较小修订
        /// 3：需较大修订
        /// 9：拒绝
        /// </summary>
        public int SuggestStatus { get; set; }

        /// <summary>
        /// 审核意见
        /// </summary>
        [Column(TypeName="text")]
        public string Suggestion { get; set; }

        public override T_AuditingRecord Find(string key)
        {
            int id = Int32.Parse(key);
            return Find(c => c.Id == id);
        }

        public override T_AuditingRecord Find(System.Linq.Expressions.Expression<Func<T_AuditingRecord, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.AuditingRecord.FirstOrDefault(where);
                this.AppendixId = item.AppendixId;
                this.CreateTime = item.CreateTime;
                this.Distributor = item.Distributor;
                this.ExamineStatus = item.ExamineStatus;
                this.Id = item.Id;
                this.JournalId = item.JournalId;
                this.LastRecord = item.LastRecord;
                this.MeetingId = item.MeetingId;
                this.ManuscriptId = item.ManuscriptId;
                this.Message = item.Message;
                this.UserName = item.UserName;
                this.Step = item.Step;
                this.ExamineFinishDate = item.ExamineFinishDate;
                this.Suggestion = item.Suggestion;
                this.SuggestStatus = item.SuggestStatus;
                this.ManuscriptType = item.ManuscriptType;
                this.Originality = item.Originality;
                this.Usefulness = item.Usefulness;
                this.Soundness = item.Soundness;
                this.LinguisticQuality = item.LinguisticQuality;
                this.Resolution = item.Resolution;
                this.Contribution = item.Contribution;
                this.Originalless = item.Originalless;
                return this;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<T_AuditingRecord, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.AuditingRecord.Any(where);
            }
        }
    }
}
